import { Entity, PrimaryGeneratedColumn, Column, Index, Tree, TreeChildren, TreeParent, BaseEntity, CreateDateColumn } from 'typeorm';

@Entity('organizations')
@Tree('materialized-path')
export class OrganizationEntity extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column('varchar', { comment: '组织名称' })
  name: string;

  @Column('int', { comment: '组织等级', nullable: true })
  level: number;

  @Column('varchar', { comment: '组织描述', nullable: true })
  description: string;

  @CreateDateColumn({ type: 'timestamp', name: 'created_at', comment: '创建时间(typeorm自动生成)' })
  @Index()
  createdAt: Date;

  @TreeChildren()
  children: OrganizationEntity[];

  @TreeParent()
  parent: OrganizationEntity;
}
